#pragma once


typedef std::string String;


class ENGINE_API StringTools
{
public:
	static String __cdecl format(const char *fmt, ...);

	static String format_arg_list(const char *fmt, va_list args);

	static inline bool StringTools::isEmpty(const String& str);
	static inline bool StringTools::isValid(const String& str);

	static inline IndexT StringTools::hashCode(const String& str);

	// trim from both ends
	static inline String & StringTools::trim(String &s) ;
	static String &ltrim(String &s) ;
	static String &rtrim(String &s) ;
};




//------------------------------------------------------------------------------
/**
*/
inline bool
StringTools::isEmpty(const String& str) 
{
	return (0 == str.length());
}

//------------------------------------------------------------------------------
/**
*/
inline bool 
StringTools::isValid(const String& str)
{
	return (0 != str.length());
}


//------------------------------------------------------------------------------
/**
	This method computes a hash code for the string. 
*/
inline IndexT
StringTools::hashCode(const String& str)
{
	IndexT hash = 0;
	const char* ptr = str.c_str();
	SizeT len = str.length();
	IndexT i;
	for (i = 0; i < len; i++)
	{
		hash += ptr[i];
		hash += hash << 10;
		hash ^= hash >>  6;
	}
	hash += hash << 3;
	hash ^= hash >> 11;
	hash += hash << 15;
	hash &= ~(1<<31);       // don't return a negative number (in case IndexT is defined signed)
	return hash;
}



// trim from both ends
inline String & StringTools::trim(String &s) 
{
		return ltrim(rtrim(s));
}